package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.RouteModel;

import admin.data.RouteData;

public class DeleteRouteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		response.setContentType("text/html");
		String path = ((HttpServletRequest) request).getRequestURI();
		String routeId = "";
		try {
			routeId = URLDecoder.decode(path.replaceAll("/admin/route/delete/", ""), "UTF-8");
		} catch (Exception e) {
			response.sendRedirect("/admin/route/list/");
		}
		try {
			RouteData routeData = new RouteData();
			RouteModel routeModel = routeData.getRoute(routeId);
			routeData.delete(routeModel);			
		} catch (Exception e) {
			// TODO: handle exception
		}
		response.sendRedirect("/admin/route/list/");
	}
}
